package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcSsdramdensityDAO;
import com.virtium.vpc.hibernate.model.VpcSsdramdensity;

public class VpcSsdramdensityManager {
	private static ArrayList<VpcSsdramdensity> arrVpcSsdramdensity = null;

	public static ArrayList<VpcSsdramdensity> getAll() {
		try {
			if (arrVpcSsdramdensity != null && arrVpcSsdramdensity.size() > 0)
				return arrVpcSsdramdensity;
			VpcSsdramdensityDAO VpcSsdramdensityDAO = DAOFactory.getInstance()
					.getVpcSsdramdensityDAO();
			arrVpcSsdramdensity = new ArrayList<VpcSsdramdensity>();
			arrVpcSsdramdensity.addAll(VpcSsdramdensityDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcSsdramdensity;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcSsdramdensity> iterObject = arrVpcSsdramdensity.listIterator();
		while(iterObject.hasNext()){
			VpcSsdramdensity object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcSsdramdensity object = new VpcSsdramdensity();
			object.setText(text);
			VpcSsdramdensityDAO ObjectDAO = DAOFactory.getInstance().getVpcSsdramdensityDAO();
			ObjectDAO.save(object);
			arrVpcSsdramdensity = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcSsdramdensityDAO ObjectDAO = DAOFactory.getInstance().getVpcSsdramdensityDAO();
			VpcSsdramdensity object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcSsdramdensity = null;
		}catch(Exception ex){
			
		}
	}
}
